﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMultiLevelModule.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-08
//    @Email			:    445267987@qq.com
//    @Module           :    NFMultiLevelModule
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFMultiLevelModule.h"

#include "NFPacketSendUtil.h"
#include "NFPlayer.h"
#include "NFSession.h"
#include "proto_cs_cmd.nanopb.h"

NFMultiLevelModule::NFMultiLevelModule(NFIPluginManager* p):NFLogicDynamicModule(p)
{
}

NFMultiLevelModule::~NFMultiLevelModule()
{
}

int NFMultiLevelModule::Awake()
{
    RegisterClientMessage(NF_ST_LOGIC_SERVER, E_CS_MULTI_LEVEL_ENTER_REQ);
    return 0;
}

int NFMultiLevelModule::OnHandleClientMessage(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);
    if (!m_pObjPluginManager->IsInited(NF_ST_LOGIC_SERVER))
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server not inited, drop client msg:{}", packet.ToString());
        return -1;
    }

    if (m_pObjPluginManager->IsServerStopping())
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server is Stopping, drop client msg:{}", packet.ToString());
        return ERR_CODE_SERVER_IS_STOPPING;
    }

    int iRetCode = 0;
    switch (packet.nMsgId)
    {
        case E_CS_MULTI_LEVEL_ENTER_REQ:
        {
            iRetCode = OnHandleMultiLevelEnterReq(packet, pSession, req);
            break;
        }
        default: NFLogError(NF_LOG_DEFAULT, 0, "not handle msg:{}", packet.nMsgId);
    }

    return iRetCode;
}

int NFMultiLevelModule::OnHandleServerMessage(uint32_t msgId, NFDataPackage& packet, uint64_t param1, uint64_t param2)
{
    return 0;
}

int NFMultiLevelModule::OnHandleMultiLevelEnterReq(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& csReq)
{
    CHECK_NULL(0, pSession);

    NFPlayer* pPlayer = pSession->GetPlayer();
    CHECK_NULL(0, pPlayer);

    proto_ff::Proto_CSRsp stRsp;
    proto_ff::Proto_CSEnterMultiLevelRsp* pRsp = stRsp.mutable_enter_multi_level_rsp();
    pRsp->set_ret((proto_ff::Proto_CS_ErrorCode)0);

    NFPacketSendUtil::SendToClient(pPlayer, proto_ff::E_CS_MULTI_LEVEL_ENTER_RSP, &stRsp);
    return 0;
}
